package com.wfh.parse;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import java.util.List;


import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.wfh.bean.TicketsBean;

public class T_Tickets implements TransForm{
	
	public List<TicketsBean> pareseJsonArray(String json){
		List<TicketsBean> list=new ArrayList<TicketsBean>();
		try {
			JSONObject jsonObject = new JSONObject(json);
			JSONArray arr=jsonObject.getJSONArray("quans");
			for(int i=0;i<arr.length();i++){
				TicketsBean bean=new TicketsBean();
				bean.setShop_id(arr.getJSONObject(i).getString("shop_id"));
				bean.setExp_date(arr.getJSONObject(i).getString("exp_date"));
				bean.setJuan_name(arr.getJSONObject(i).getString("juan_name"));
				bean.setJuan_id(arr.getJSONObject(i).getString("juan_id"));
				bean.setReal_money(arr.getJSONObject(i).getString("real_money"));
				bean.setReduce_money(arr.getJSONObject(i).getString("reduce_money"));
				if(!arr.getJSONObject(i).isNull("code")){
					bean.setCode(arr.getJSONObject(i).getString("code"));
				}
				if(!arr.getJSONObject(i).isNull("status")){
					bean.setStatus(arr.getJSONObject(i).getString("status"));
				}
				list.add(bean);
			}
			//Log.i("list",list.size()+"");
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		return list;
	}

	@Override
	public Map<String,String> pareseJsonObject(String json) {
		Map<String,String> map=new HashMap<String,String>();
		try {
			JSONObject jsonObject = new JSONObject(json);
			if(!jsonObject.isNull("ret")){
				map.put("ret", jsonObject.getString("ret"));
			}
			if(!jsonObject.isNull("module")){
				map.put("module", jsonObject.getString("module"));
			}
			if(!jsonObject.isNull("version")){
				map.put("version", jsonObject.getString("version"));
			}
			if(!jsonObject.isNull("shop_id")){
				map.put("shop_id", jsonObject.getString("shop_id"));
			}
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return map;
	}

	@Override
	public Object pareseJsonBean(String json) {
		return null;
	}
	
}
